/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package telas;

import javax.swing.JOptionPane;
import usuario.UsuarioDAO;
import usuario.Usuario;

/**
 *
 * @author Max Weber
 */
public class O3TelaCadastrarUsuario extends javax.swing.JFrame {

    /**
     * Creates new form TelaCadastrarUsuarioTeste
     */
    public O3TelaCadastrarUsuario() {
        initComponents();
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        tfNomeUsuario = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tfLogin = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tfSenha = new javax.swing.JPasswordField();
        jLabel7 = new javax.swing.JLabel();
        tfConfirmarSenha = new javax.swing.JPasswordField();
        jcTipoDeUsuario = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SISVATEC - Sistema de Vacinação");
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel2.setBackground(new java.awt.Color(10, 66, 108));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel3.setBackground(new java.awt.Color(0, 114, 180));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/add-user.png"))); // NOI18N
        jPanel3.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, 50));

        jLabel1.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 36)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Cadastrar Usuário");
        jPanel3.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 20, -1, -1));

        jPanel2.add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 440, 63));

        jPanel1.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 450, 70));

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
        jPanel6.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel4.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel4.setText("Nome do usuário:");
        jPanel6.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, -1));

        tfNomeUsuario.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        tfNomeUsuario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 114, 180), 2));
        jPanel6.add(tfNomeUsuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 350, 30));

        jLabel5.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel5.setText("Login:");
        jPanel6.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, -1, -1));

        tfLogin.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        tfLogin.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 114, 180), 2));
        jPanel6.add(tfLogin, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, 270, 30));

        jLabel6.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel6.setText("Senha:");
        jPanel6.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, -1, -1));

        tfSenha.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        tfSenha.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 114, 180), 2));
        jPanel6.add(tfSenha, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 180, 270, 30));

        jLabel7.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel7.setText("Confirmar senha:");
        jPanel6.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 220, -1, -1));

        tfConfirmarSenha.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        tfConfirmarSenha.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 114, 180), 2));
        jPanel6.add(tfConfirmarSenha, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 250, 270, 30));

        jcTipoDeUsuario.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        jcTipoDeUsuario.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administrador", "Comum" }));
        jcTipoDeUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcTipoDeUsuarioActionPerformed(evt);
            }
        });
        jPanel6.add(jcTipoDeUsuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 300, 160, -1));

        jLabel10.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel10.setText("Tipo de usuário:");
        jPanel6.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 300, -1, -1));

        jPanel1.add(jPanel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, 380, 350));

        jPanel7.setBackground(new java.awt.Color(10, 66, 108));
        jPanel7.setLayout(new java.awt.GridBagLayout());

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Check-32.png"))); // NOI18N
        jPanel7.add(jLabel3, new java.awt.GridBagConstraints());

        jLabel8.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setText("  Cadastrar");
        jLabel8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel8MouseClicked(evt);
            }
        });
        jPanel7.add(jLabel8, new java.awt.GridBagConstraints());

        jPanel1.add(jPanel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 450, 130, 30));

        jPanel8.setBackground(new java.awt.Color(10, 66, 108));
        jPanel8.setLayout(new java.awt.GridBagLayout());

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Delete-32.png"))); // NOI18N
        jPanel8.add(jLabel12, new java.awt.GridBagConstraints());

        jLabel9.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(255, 255, 255));
        jLabel9.setText("  Cancelar");
        jPanel8.add(jLabel9, new java.awt.GridBagConstraints());

        jPanel1.add(jPanel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 450, 130, 30));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 440, 500));

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel8MouseClicked
        Usuario usuario = new Usuario();
        usuario.setNome_usuario(tfNomeUsuario.getText());
        usuario.setLogin(tfLogin.getText());
        //verifica se as senhas conferem
        if(tfSenha.getText().equals(tfConfirmarSenha.getText())){
            usuario.setSenha(tfSenha.getText());
            usuario.setTipo(jcTipoDeUsuario.getSelectedItem().toString());
            
        
            UsuarioDAO dao = new UsuarioDAO();
            dao.adicionar(usuario);
            JOptionPane.showMessageDialog(rootPane, "Usuário cadastrado com sucesso!");
            limparCampos();
            
        } else {
            JOptionPane.showMessageDialog(rootPane, "Senhas não conferem");
        }
        
    }//GEN-LAST:event_jLabel8MouseClicked

    private void jcTipoDeUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcTipoDeUsuarioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jcTipoDeUsuarioActionPerformed

    public void limparCampos(){
        tfNomeUsuario.setText("");
        tfLogin.setText("");
        tfSenha.setText("");
        tfConfirmarSenha.setText(null);
    }
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(O3TelaCadastrarUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(O3TelaCadastrarUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(O3TelaCadastrarUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(O3TelaCadastrarUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new O3TelaCadastrarUsuario().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JComboBox jcTipoDeUsuario;
    private javax.swing.JPasswordField tfConfirmarSenha;
    private javax.swing.JTextField tfLogin;
    private javax.swing.JTextField tfNomeUsuario;
    private javax.swing.JPasswordField tfSenha;
    // End of variables declaration//GEN-END:variables
}
